﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ysb.Components;
using Model;
using BLL;
 
public partial class Admin_News_Edit : System.Web.UI.Page
{
    Model.NewsSysTem newssystem = new Model.NewsSysTem();
    BLL.NewsSysTemService newservice = new NewsSysTemService();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (AdminCheck.Check(this, 1))
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["area"] == "edit")
                {
                    DataLoad();
                    ViewState["BackUrl"] = Request.UrlReferrer.ToString();
                }
            }
        }
        else
        {
            Response.Redirect(AdminCheck.RedirectPage);
        }


    }


    private void DataLoad()
    {
      
     newssystem=newservice.GetNews(Convert.ToInt32(Request.QueryString["id"]));
     titletxt.Value = newssystem.NewsTitle;
     this.WebEdit.Value = newssystem.NewContent;
 
 
    }

    protected void okbtn_Click1(object sender, ImageClickEventArgs e)
    {


        newssystem.NewsTitle = titletxt.Value;
        newssystem.NewContent = this.WebEdit.Value;
        newssystem.NewsState = 0;
        newssystem.Summary = "";
        if (Request.QueryString["area"] == "edit")
        {
            newssystem.NewsID = Convert.ToInt32(Request.QueryString["id"]);

            if (newservice.Update(newssystem) == 1)
            {
                Jscript.AlertAndRedirect("修改成功", ViewState["BackUrl"].ToString());

            }
            else
            {
                Jscript.AlertAndRedirect("修改出错", HttpContext.Current.Request.Url.PathAndQuery);

            }
        }
        else
        {


            if (   newservice. Insert(newssystem) == 1)
            {


         
         //       string ExcelFileName = Path.Combine(  ApplicationInfo.PhysicalApplicationPath, "textBanner.xml");
         //       if (File.Exists(ExcelFileName))
         //       {
         //           File.Delete(ExcelFileName);
         //       }
         //       StreamWriter writer = new StreamWriter(ExcelFileName, false);
         //       writer.WriteLine(" <?xml version=\"1.0\" encoding=\"gb2312\"?>");
         //       writer.WriteLine("<news>");
         //DataTable dt =newservice.GetbyCount();
         //       for(int i=0;i<dt.Rows.Count;i++)
         //       {
         //            writer.WriteLine("<content>");
         //            writer.WriteLine("<标题>"+dt.Rows[i]["Title"]+"</标题>");
         //            writer.WriteLine("<链接>/News.aspx?ID=" + dt.Rows[i]["Nid"] + "</链接>");
         //            writer.WriteLine("</content>");
         //       }

   
         //       writer.WriteLine(" </news>");
         //       writer.Close();

                Jscript.AlertAndRedirect("添加成功", "News_Manage.aspx");
            }
            else
            {
                Jscript.AlertAndRedirect("添加出错", HttpContext.Current.Request.Url.PathAndQuery);

            }
        }
    }

  
}
